﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%
    if (Request.IsAuthenticated) {
%>
<ul class="nav top-menu">
    <!-- BEGIN SETTINGS -->
    <%
        //List<VietThuongLMS.HocVien_Lop> list = new List<VietThuongLMS.HocVien_Lop>();
        List < VietThuongLMS.HocVien_Lop > list = new List<VietThuongLMS.HocVien_Lop>();
        VietThuongLMS.LMSDataEntities Context = new VietThuongLMS.LMSDataEntities();
        list = Context.HocVien_Lop.Join(Context.LopHocs,
            hvl => hvl.MaLopHoc,
            lh => lh.ID,
            (hvl, lh) => hvl).Where(hvl => hvl.DongHocPhi == VietThuongLMS.Utils.Constant.HOCPHI_CHUADONG).Distinct().ToList();

        int maLop = 0;
        int countLop = 0;

        int maHocVien = 0;
        int countHocVien = 0;
        
        if (list != null && list.Count > 0)
        {
            countLop = 1;
            countHocVien = 1;
            maLop = int.Parse(list.ElementAt(0).MaLopHoc.ToString());
            maHocVien = int.Parse(list.ElementAt(0).MaHocVien.ToString());
            foreach (VietThuongLMS.HocVien_Lop hv in list)
            {
                //Count lop hoc
                if (maLop != hv.MaLopHoc)
                {
                    countLop++;
                }
                
                //Count hocvien
                if (maHocVien != hv.MaHocVien)
                {
                    countHocVien++;
                }
                                
                hv.LopHocReference.Load();
                hv.HocVienReference.Load();
                hv.HocVienReference.Value.TaiKhoanReference.Load();

            }
        }
    %>
<%--    <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><i
        class="icon-tasks"></i><span class="badge badge-important"><%= countLop %></span> </a>
        <ul class="dropdown-menu extended tasks-bar">
            <li>
                <p>
                    Bạn có <%= countLop %> lớp học cần thu học phí</p>
            </li>
            <%
                if (list != null && list.Count() > 0)
                {
                    int i;
                    maLop = int.Parse(list.ElementAt(0).MaLopHoc.ToString());
                    for (i = 0; i < list.Count(); i++)
                    {
                        if (maLop != list.ElementAt(i).MaLopHoc)
                        {
                     %>
                        <li>
                            <a href="<%=ResolveUrl("~/Admin/LopHoc/Detail/")%><%= list.ElementAt(i).MaLopHoc %>">
                                <%=
                                    list.ElementAt(i).LopHocReference.Value.TenLopHoc
                                %>   
                            </a>
                        </li>
                    <% }
                    }
                    %>
                        <li>
                            <a href="<%=ResolveUrl("~/Admin/LopHoc/Detail/")%><%= list.ElementAt(0).MaLopHoc %>">
                                <%=
                                    list.ElementAt(0).LopHocReference.Value.TenLopHoc
                                %>   
                            </a>
                        </li>  
                    <%
                }
                %>
            
            <li class="external"><a href="<%=ResolveUrl("~/Admin/LopHoc/Index") %>">Xem tất cả</a> </li>
        </ul>
    </li>--%>
    <!-- END SETTINGS -->
    <!-- BEGIN INBOX DROPDOWN -->
    <li class="dropdown" id="header_inbox_bar"><a href="#" class="dropdown-toggle" data-toggle="dropdown">
        <i class="icon-envelope-alt"></i><span class="badge badge-important"><%= countHocVien %></span> </a>
        <ul class="dropdown-menu extended inbox">
            <li>
                <p>Bạn có <%= countHocVien %> học viên cần thu học phí</p>
            </li>

            <%
                if (list != null && list.Count() > 0)
                {
                    int i;
                    int count = 1;
                    maHocVien = int.Parse(list.ElementAt(0).MaHocVien.ToString());
                    for (i = 0; i < list.Count(); i++)
                    {
                        if (maHocVien != list.ElementAt(i).MaHocVien)
                        {
                            count++;
                            if (count > 10)
                                break;
                     %>
                        <li>
                            <a href="<%=ResolveUrl("~/Admin/HocVien/Detail/")%><%= list.ElementAt(i).MaHocVien %>">
                                <%=
                                    list.ElementAt(i).HocVienReference.Value.TaiKhoanReference.Value.HoTen
                                %>   
                            </a>
                        </li>
                    <% }
                    }
                    %>
                        <li>
                            <a href="<%=ResolveUrl("~/Admin/HocVien/Detail/")%><%= list.ElementAt(0).MaHocVien %>">
                                <%=
                                    list.ElementAt(0).HocVienReference.Value.TaiKhoanReference.Value.HoTen
                                %>   
                            </a>
                        </li>  
                    <%
                }                    
            %>

            <li><a href="<%=ResolveUrl("~/Admin/HocVien/HocVienThuPhi") %>">Xem tất cả</a> </li>
        </ul>
    </li>
    <!-- END INBOX DROPDOWN -->
    <!-- BEGIN NOTIFICATION DROPDOWN -->
    <%--<li class="dropdown" id="header_notification_bar"><a href="#" class="dropdown-toggle"
        data-toggle="dropdown"><i class="icon-bell-alt"></i><span class="badge badge-warning">
            7</span> </a>
        <ul class="dropdown-menu extended notification">
            <li>
                <p>
                    You have 7 new notifications</p>
            </li>
            <li><a href="#"><span class="label label-important"><i class="icon-bolt"></i></span>
                Server #3 overloaded. <span class="small italic">34 mins</span> </a></li>
            <li><a href="#"><span class="label label-warning"><i class="icon-bell"></i></span>Server
                #10 not respoding. <span class="small italic">1 Hours</span> </a></li>
            <li><a href="#"><span class="label label-important"><i class="icon-bolt"></i></span>
                Database overloaded 24%. <span class="small italic">4 hrs</span> </a></li>
            <li><a href="#"><span class="label label-success"><i class="icon-plus"></i></span>New
                user registered. <span class="small italic">Just now</span> </a></li>
            <li><a href="#"><span class="label label-info"><i class="icon-bullhorn"></i></span>Application
                error. <span class="small italic">10 mins</span> </a></li>
            <li><a href="#">See all notifications</a> </li>
        </ul>
    </li>--%>
    <!-- END NOTIFICATION DROPDOWN -->
    </ul>
    <%} %>